From 450056cdfe5cbf6fdff9c9def77570d37c0b3cd4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 16 Sep 2015 07:39:19 -0700 Subject: [PATCH] file chooser: Avoid a crash When right-clicking in an empty folder, you should get a context menu, not a crash. The code for positioning the popover was not handling the eventuality of no row under the pointer. Just position the popover right at the click location in this case. https://bugzilla.gnome.org/show_bug.cgi?id=755021 --- gtk/gtkfilechooserwidget.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 8c25741bb9..d286fcf086 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -2312,18 +2312,27 @@ file_list_show_popover (GtkFileChooserWidget *impl, selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view)); list = gtk_tree_selection_get_selected_rows (selection, &model); - path = list->data; - gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect); - gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view), + if (list) + { + path = list->data; + gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect); + gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view), rect.x, rect.y, &rect.x, &rect.y); - rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40); - rect.width = 40; + rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40); + rect.width = 40; - g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + } + else + { + rect.x = x; + rect.y = y; + rect.width = 1; + rect.height = 1; + } gtk_popover_set_pointing_to (GTK_POPOVER (priv->browse_files_popover), &rect); - gtk_widget_show (priv->browse_files_popover); } -- 2.30.2